package com.xiangban.controller;

import com.xiangban.aop.Permission;
import com.xiangban.model.AccompanyReceiveOrder;
import com.xiangban.model.AccompanyReceiveStatus;
import com.xiangban.model.Order;
import com.xiangban.model.OrderComment;
import com.xiangban.model.dto.AccompanyReceiveStatusDto;
import com.xiangban.model.dto.OrderDto;
import com.xiangban.model.res.ApiResult;
import com.xiangban.model.vo.OrderVo;
import com.xiangban.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @Author Mr. MaYaYun
 * @Data 2021/12/8 14:29
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @RequestMapping("/estimateOrderMoney")
    @ApiOperation("预估订单价格")
    @Permission(permission = "admin:order:estimateOrderMoney")
    public ApiResult<Object> estimateOrderMoney(@RequestBody Order order){
        return ApiResult.newSuccess(orderService.estimateOrderMoney(order));
    }

    @RequestMapping("/createOrder")
    @ApiOperation("创建订单")
    @Permission(permission = "admin:order:createOrder")
    public ApiResult<Object> createOrder(@RequestBody Order order) throws ParseException {
        orderService.createOrder(order);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/cancelOrder")
    @ApiOperation("取消订单")
    @Permission(permission = "admin:order:cancelOrder")
    public ApiResult<Object> cancelOrder(@RequestBody Order order){
        orderService.cancelOrder(order);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/finishOrder")
    @ApiOperation("结束订单(违约单)")
    @Permission(permission = "admin:order:finishOrder")
    public ApiResult<Object> finishOrder(@RequestBody Order order){
        orderService.finishOrder(order);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/remarkOrVisit")
    @ApiOperation("订单备注")
    @Permission(permission = "admin:order:remarkOrVisit")
    public ApiResult<Object> remarkOrVisit(@RequestBody Order order) {
        orderService.remarkOrVisit(order);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/listOrderPage")
    @ApiOperation("列表订单")
    @Permission(permission = "admin:order:listOrderPage")
    public ApiResult<Object> listOrderPage(@RequestBody OrderVo orderVo){
        return ApiResult.newSuccess(orderService.listOrderPage(orderVo));
    }

    @RequestMapping("/getOrder")
    @ApiOperation("详情订单")
    @Permission(permission = "admin:order:getOrder")
    public ApiResult<Object> getOrder(@RequestBody OrderVo orderVo){
        return ApiResult.newSuccess(orderService.getOrder(orderVo));
    }

    @RequestMapping("/listAccompanyReceiveStatus")
    @ApiOperation("订单服务状态")
    @Permission(permission = "admin:order:listAccompanyReceiveStatus")
    public ApiResult<Object> listAccompanyReceiveStatus(@RequestBody AccompanyReceiveStatusDto receiveStatusDto){
        return ApiResult.newSuccess(orderService.listAccompanyReceiveStatus(receiveStatusDto));
    }

    @RequestMapping("/getMedicalData")
    @ApiOperation("就医凭证")
    @Permission(permission = "admin:order:getMedicalData")
    public ApiResult<Object> getMedicalData(@RequestBody AccompanyReceiveOrder receiveOrder){
        return ApiResult.newSuccess(orderService.getMedicalData(receiveOrder));
    }

    @RequestMapping("/updateMedicalData")
    @ApiOperation("修改就医凭证")
    @Permission(permission = "admin:order:updateMedicalData")
    public ApiResult<Object> updateMedicalData(@RequestBody AccompanyReceiveOrder receiveOrder){
        orderService.updateMedicalData(receiveOrder);
        return ApiResult.newSuccess();
    }

    @RequestMapping("/getServiceRating")
    @ApiOperation("服务评价")
    @Permission(permission = "admin:order:getServiceRating")
    public ApiResult<Object> getServiceRating(@RequestBody OrderComment orderComment){
        return ApiResult.newSuccess(orderService.getServiceRating(orderComment));
    }

    @RequestMapping("/telephoneInterviews")
    @ApiOperation("电话回访")
    @Permission(permission = "admin:order:telephoneInterviews")
    public ApiResult<Object> telephoneInterviews(@RequestBody Order order){
        orderService.telephoneInterviews(order);
        return ApiResult.newSuccess();
    }
}
